﻿using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

public class SeeThroughTrigger : MonoBehaviour
{
    [CompilerGenerated]
    private static Action<RendererFader> <>f__am$cache6;
    public float destAlpha = 0.2f;
    private HashSet<RendererFader> enteredFaders = new HashSet<RendererFader>();
    public float fadeSpeed = 5f;
    public LayerMask layerMask;
    public Shader shader;
    private Collider trigger;

    private void Awake()
    {
        this.trigger = base.GetComponent<Collider>();
    }

    private void OnDisable()
    {
        if (<>f__am$cache6 == null)
        {
            <>f__am$cache6 = (Action<RendererFader>) (x => (x.destAlpha = 1f));
        }
        this.enteredFaders.Foreach<RendererFader>(<>f__am$cache6);
    }

    private void OnEnable()
    {
        this.trigger.enabled = false;
        this.trigger.enabled = true;
    }

    private void OnTriggerEnter(Collider co)
    {
        if (base.enabled && this.layerMask.ContainsFlag(co.gameObject.layer))
        {
            foreach (MeshRenderer renderer in co.GetComponentsInChildren<MeshRenderer>())
            {
                RendererFader orAddComponent = renderer.gameObject.GetOrAddComponent<RendererFader>();
                orAddComponent.shader = this.shader;
                orAddComponent.destAlpha = this.destAlpha;
                orAddComponent.speed = this.fadeSpeed;
                this.enteredFaders.Add(orAddComponent);
            }
        }
    }

    private void OnTriggerExit(Collider co)
    {
        if (base.enabled && this.layerMask.ContainsFlag(co.gameObject.layer))
        {
            foreach (MeshRenderer renderer in co.GetComponentsInChildren<MeshRenderer>())
            {
                RendererFader orAddComponent = renderer.gameObject.GetOrAddComponent<RendererFader>();
                orAddComponent.destAlpha = 1f;
                orAddComponent.speed = this.fadeSpeed;
                this.enteredFaders.Add(orAddComponent);
            }
        }
    }

    private void Start()
    {
    }
}

